<?php
/**
 * autoloader.php
 * 
 * Created on 2015-07-09
 * Create by yuebin
 */

namespace haibao\classlibrary;
class Autoloader {
	public static function autoLoad($className){
		$nameSpacePre = 'haibao\classlibrary';
		$fileArr = explode('\\', $className);
		$fileName = '';
		if(count($fileArr) > 2 && $fileArr[1] != 'classlibrary'){
			$fileName = '\\' .$fileArr[1];
			$nameSpacePre = $fileArr[0].'\\'.$fileArr[1];
		}
		$end = strlen($className);
		$start = strlen($nameSpacePre);
		if ($end > $start){
			if (substr($className,0,$start) == $nameSpacePre){
				$file = dirname(__FILE__) . $fileName.strtolower(substr($className,$start,$end)) . '.php';
				$file = str_replace('\\', DIRECTORY_SEPARATOR, $file);
				if (file_exists($file)){
					include_once $file;
				}
			}
		}
	}
}

spl_autoload_register(array('haibao\classlibrary\Autoloader','autoLoad'));
